package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.web.SkuDetailVo;
import com.atguigu.gmall.feign.item.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author:ahang
 * @create:2022-10-03 23:54
 * @Description:
 */
@Controller
public class ItemController {

    @Autowired
    ItemFeignClient itemFeignClient;

    @GetMapping("/{skuId}.html")
    public String item(@PathVariable("skuId") Long skuId, Model model){
        //远程调用服务
        Result<SkuDetailVo> skuDetailVoResult = itemFeignClient.skuDetail(skuId);
        SkuDetailVo skuDetailVo = skuDetailVoResult.getData();

        //1.当前sku所属的完整分类信息
        //{category1Id,category1Name,category2Id,category2Name,category3Id,category3Name}
        model.addAttribute("categoryView",skuDetailVo.getCategoryView());
        //2.当前sku的信息(基本信息,图片列表)
        //{id,skuName,skuDefaultImg,skuImageList(imgUrl),skuName}
        model.addAttribute("skuInfo",skuDetailVo.getSkuInfo());
        //3.当前sku的价格
        model.addAttribute("price",skuDetailVo.getPrice());
        //4.当前sku的销售属性列表
        model.addAttribute("spuSaleAttrList",skuDetailVo.getSpuSaleAttrList());
        //5.json值
        model.addAttribute("valuesSkuJson",skuDetailVo.getValueSkuJson());
        return "item/index";
    }
}
